/**  
 * Project Name:mms_svn  
 * File Name:Shift.java  
 * Package Name:com.mes.schedule.persistence.domain  
 * Date:Dec 28, 20168:54:07 PM  
 * Copyright (c) 2016, MM-MES All Rights Reserved.  
 */

package com.mes.schedule.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * ClassName:Shift <br/> Function: TODO 定义日历的班次信息. <br/> Reason: TODO ADD
 * REASON. <br/> Date: Dec 28, 2016 8:54:07 PM <br/>
 * 
 * @author lcs
 * @version
 * @since JDK 1.8
 * @see
 */
public class Shift {
	/**
	 * 班产id，1表示白班，2表示中班，3表示晚班，4....
	 */
	private int shiftId;
	/**
	 * 班次名称
	 */
	private String shiftName;
	/**
	 * 班次日期
	 */
	private Date shiftTimeDate;
	/**
	 * 班次开始时间
	 */
	private Date shiftStartTime;
	/**
	 * 班次结束时间
	 */
	private Date shiftEndTime;
	/**
	 * 班次开始片段
	 */
	private int shiftStartSegment;
	/**
	 * 班次结束片段
	 */
	private int shiftEndSegment;
	/**
	 * 班次所在的日历编号
	 */
	private String calendarUid;
	/**
	 * 班次所在的日历对象
	 */
	private SCalendar sCalendar;
	/**
	 * 设置班次可用时间（分钟）
	 */
	private double availableShiftTime;
	/**
	 * 班次内安排的任务（计划开始在此班次内的任务）
	 */
	private List<SOperationTask> shiftOpList = new ArrayList<SOperationTask>();

	public int getShiftId() {
		return shiftId;
	}

	public void setShiftId(int shiftId) {
		this.shiftId = shiftId;
	}

	public String getShiftName() {
		return shiftName;
	}

	public void setShiftName(String shiftName) {
		this.shiftName = shiftName;
	}

	public Date getShiftTimeDate() {
		return shiftTimeDate;
	}

	public void setShiftTimeDate(Date shiftTimeDate) {
		this.shiftTimeDate = shiftTimeDate;
	}

	public Date getShiftStartTime() {
		return shiftStartTime;
	}

	public void setShiftStartTime(Date shiftStartTime) {
		this.shiftStartTime = shiftStartTime;
	}

	public Date getShiftEndTime() {
		return shiftEndTime;
	}

	public void setShiftEndTime(Date shiftEndTime) {
		this.shiftEndTime = shiftEndTime;
	}

	public int getShiftStartSegment() {
		return shiftStartSegment;
	}

	public void setShiftStartSegment(int shiftStartSegment) {
		this.shiftStartSegment = shiftStartSegment;
	}

	public int getShiftEndSegment() {
		return shiftEndSegment;
	}

	public void setShiftEndSegment(int shiftEndSegment) {
		this.shiftEndSegment = shiftEndSegment;
	}

	public String getCalendarUid() {
		return calendarUid;
	}

	public void setCalendarUid(String calendarUid) {
		this.calendarUid = calendarUid;
	}

	public SCalendar getSCalendar() {
		return sCalendar;
	}

	public void setSCalendar(SCalendar calendar) {
		sCalendar = calendar;
	}

	public List<SOperationTask> getShiftOpList() {
		return shiftOpList;
	}

	public void setShiftOpList(List<SOperationTask> shiftOpList) {
		this.shiftOpList = shiftOpList;
	}

	public double getAvailableShiftTime() {
		return availableShiftTime;
	}

	public void setAvailableShiftTime(double availableShiftTime) {
		this.availableShiftTime = availableShiftTime;
	}

	/**
	 * 返回班次占用时间 这个地方要修改，因为不能按照调度工序任务，而是班产任务
	 * 
	 * @return
	 */
	public double getOccupiedShiftTime() {
		double occupiedShiftTime = 0;
		for (SOperationTask opTask : shiftOpList) {
			if (opTask.getCompleteQty() > 0
					|| opTask.getTaskState() == SOperationTask.TASKSTATE_PREPARE_COMPLETED) {
				occupiedShiftTime += (opTask.getPlanQty() - opTask
						.getCompleteQty())
						* opTask.getEstiRunTime();
			} else {
				occupiedShiftTime += (opTask.getPlanQty() - opTask
						.getCompleteQty())
						* opTask.getEstiRunTime() + opTask.getEstiPreTime();
			}
		}
		return occupiedShiftTime;
	}
}
